package com.fhd.utils;

import java.sql.Date;
import java.sql.Time;
import java.text.SimpleDateFormat;

public class DateTimeUtil {
    // 将String转成Time
    public static Time stringToTime(String str) {
        Time time = null;
        try {
            // String 转成 Time
            SimpleDateFormat format = new SimpleDateFormat("HH:mm");
            time = new Time(format.parse(str).getTime()) ;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return time;
    }

    // 将String转成Date
    public static Date stringToDate(String str) {
        Date date = null;
        try {
            // String 转成 Time
            SimpleDateFormat format = new SimpleDateFormat("yy-MM-dd");
            date = (Date) format.parse(str);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return date;
    }


    // 获取当前日期截成只包含年月日
    public static Date getNowDate() {
        return new Date(System.currentTimeMillis());
    }
}
